package com.quectel.emp.controller.dept;

import cn.hutool.core.lang.func.LambdaUtil;
import com.quectel.business.common.thirdconfig.ThirdPlatformConfigBusiness;
import com.quectel.constant.core.officialaccount.OfficialAccountsConstants;
import com.quectel.constant.global.SMSConstants;
import com.quectel.constant.global.SystemConstants;
import com.quectel.core.module.dept.dto.DeptPersonDto;
import com.quectel.core.module.dept.service.DeptPersonService;
import com.quectel.core.module.officialaccounts.dto.OfficialAccountsBindingDto;
import com.quectel.core.module.officialaccounts.service.OfficialAccountsBindingService;
import com.quectel.core.module.thirdconfig.dto.item.WechatOfficial;
import com.quectel.core.module.village.dto.VillageDto;
import com.quectel.core.module.village.service.VillageService;
import com.quectel.emp.constants.EmpRedisCacheConstants;
import com.quectel.emp.controller.BaseController;
import com.quectel.emp.interceptor.LoginEmpSession;
import com.quectel.emp.util.SessionHolder;
import com.quectel.emp.util.SmsComponent;
import com.quectel.emp.vo.deptperson.EmpBaseInfoWithMobileVo;
import com.quectel.emp.vo.deptperson.login.*;
import com.quectel.sdk.officialaccounts.OfficialAccountsUtils;
import com.quectel.sys.module.sys.service.SysTenantService;
import com.quectel.util.common.JacksonUtils;
import com.quectel.util.common.PasswordUtils;
import com.quectel.util.common.Response;
import com.quectel.util.ex.CheckErrorException;
import com.quectel.util.redis.RedisUtils;
import com.quectel.util.security.TokenUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * @author caolu
 * @email louis.cao@quectel.com
 */
@RestController
@RequestMapping("deptPerson")
@Tag(name = "DeptPersonController", description = "员工登录修改等相关的api")
public class DeptPersonController extends BaseController {
    @DubboReference
    private VillageService villageService;
    @DubboReference
    private DeptPersonService deptPersonService;
    @DubboReference
    private OfficialAccountsBindingService officialAccountsBindingService;
    @DubboReference
    private SysTenantService sysTenantService;
    @Autowired
    private SmsComponent smsCompnent;

    @Autowired
    private ThirdPlatformConfigBusiness thirdPlatformConfigBusiness;


    @PostMapping("JSAPI/login")
    @Operation(summary = "JSAPI登录接口,获取token,后续请求需要在请求头中加入token")
    public Response<LoginEmpSession> JSAPILogin(@RequestBody JSAPILoginVo loginVo) {

        logger.debug("微信用户获取openId，请求参数：code=" + JacksonUtils.toJsonString(loginVo));

        VillageDto villageDto = villageService.selectByCode(loginVo.getVillageCode());
        if (villageDto == null) {
            return Response.error("链接错误请检查");
        }

        LoginEmpSession session = new LoginEmpSession();
        session.setLoginType(SystemConstants.LoginType.JS_API.getType());
        session.setOfficialAccountsType(loginVo.getOfficialAccountsType());

        String openId = null;
        if (SystemConstants.OFFICIAL_ACCOUNTS_PLATFORM_WX.equals(loginVo.getOfficialAccountsType())) {
            WechatOfficial wechatOfficialConfig = thirdPlatformConfigBusiness.getWechatOfficialConfig(villageDto.getTenantId());

            if (wechatOfficialConfig == null) {
                throw new CheckErrorException("公众号没有配置");
            }
            session.setAppId(wechatOfficialConfig.getAppId());

            //查询配置 获取微信用户唯一id
            openId = OfficialAccountsUtils.getWxJsApiUserId(wechatOfficialConfig.getAppId(),
                    wechatOfficialConfig.getAppSecret(), loginVo.getCode());
        }

        if (StringUtils.isBlank(openId)) {
            return Response.error("无法获取用户信息");
        }


        session.setOfficialAccountsType(loginVo.getOfficialAccountsType());
        session.setOpenId(openId);
        session.setToken(TokenUtils.genRandomToken());

        //查看是否有绑定
        OfficialAccountsBindingDto officialAccountsBindingDto = officialAccountsBindingService.selectBy(
                loginVo.getOfficialAccountsType(),
                loginVo.getAppId(),
                openId,
                OfficialAccountsConstants.PERSON_TYPE_EMP
        );
        if (officialAccountsBindingDto != null) {
            //已绑定
            DeptPersonDto deptPersonDto = deptPersonService.selectById(officialAccountsBindingDto.getPersonId());
            if (SystemConstants.NO.equals(deptPersonDto.getStatus())) {
                return Response.error("当前用户已锁定");
            }
            if (!Objects.equals(deptPersonDto.getVillageId(), villageDto.getId())) {
                //此人已经绑定过公众号，但是当前访问的链接所携带的villageCode和上次登录身份的villageCode不一致 ，我们认为他没有登录过当前社区
                //设置为null模拟他没有登录过
                session.setDeptPersonDto(null);
            } else {
                session.setDeptPersonDto(deptPersonDto);
            }

        }

        return Response.<LoginEmpSession>ok().wrap(SessionHolder.resetLoginEmpSession(session));
    }

    @GetMapping("getWxJSSDKConfig")
    @Operation(summary = "微信的配置信息")
    public Response<Object> getWxJSSDKConfig(@RequestParam String currentPageUrl) {

        LoginEmpSession loginMobileUserSession = SessionHolder.getLoginEmpSession();


        WechatOfficial wechatOfficialConfig = thirdPlatformConfigBusiness.getWechatOfficialConfig(loginMobileUserSession.getDeptPersonDto().getTenantId());

        if (wechatOfficialConfig == null) {
            throw new CheckErrorException("公众号没有配置");
        }

        Map<String, String> wxJSSDKConfig = OfficialAccountsUtils.getWxJSSDKConfig(wechatOfficialConfig.getAppId(), wechatOfficialConfig.getAppSecret(), currentPageUrl);

        return Response.ok().wrap(wxJSSDKConfig);

    }


    /**
     * 发送验证码
     *
     * @return
     */
    @PostMapping("sendBindingMsgCode")
    @Operation(summary = "发送绑定公众号验证码")
    public Response<Object> sendBindingMsgCode(@RequestBody SendVerCodeVo sendVerCodeVo) {

        VillageDto villageDto = villageService.selectByCode(sendVerCodeVo.getVillageCode());
        if (villageDto == null) {
            return Response.error("社区不存在，请检查访问链接");
        }
        DeptPersonDto deptPersonDto = deptPersonService.selectByVillageAndMobile(villageDto.getId(), sendVerCodeVo.getMobile());
        if (deptPersonDto == null) {
            return Response.error("您的个人信息不存在，请联系管理员添加");
        }
        if (SystemConstants.ABNORMAL.equals(deptPersonDto.getStatus())) {
            return Response.error("用户已被禁用");
        }
        String code = smsCompnent.sendVerCode(villageDto.getTenantId(), sendVerCodeVo.getMobile(), SMSConstants.VerCodeType.EMP_OFFICIAL_ACCOUNTS_BINDING);
        if (code == null) {
            return Response.error("发送验证码失败");
        }

        return Response.ok().wrap(thirdPlatformConfigBusiness.smsMockEnable(villageDto.getTenantId()) ? code : null);
    }

    /**
     * 绑定个人信息
     *
     * @return
     */
    @PostMapping("binding")
    @Operation(summary = "绑定公众号信息")
    public Response<LoginEmpSession> binding(@RequestBody EmpBaseInfoWithMobileVo baseInfoWithMobile) {


        boolean isLegal = smsCompnent.checkVerCode(baseInfoWithMobile.getMobile(), baseInfoWithMobile.getVerCode(), SMSConstants.VerCodeType.EMP_OFFICIAL_ACCOUNTS_BINDING);
        if (!isLegal) {
            //输入错误就要作废
            smsCompnent.invalidVerCode(baseInfoWithMobile.getMobile(), SMSConstants.VerCodeType.EMP_OFFICIAL_ACCOUNTS_BINDING);
            return Response.error("您输入验证码不正确或者不在有效期内,请重新发送验证码");
        }
        //使用以后过期
        smsCompnent.invalidVerCode(baseInfoWithMobile.getMobile(), SMSConstants.VerCodeType.EMP_OFFICIAL_ACCOUNTS_BINDING);

        Date date = new Date();

        LoginEmpSession empSession = SessionHolder.getLoginEmpSession();

        VillageDto villageDto = villageService.selectByCode(baseInfoWithMobile.getVillageCode());
        if (villageDto == null) {
            return Response.error("社区不存在，请检查访问链接");
        }

        DeptPersonDto deptPersonDto = deptPersonService.selectByVillageAndMobile(villageDto.getId(), baseInfoWithMobile.getMobile());
        if (deptPersonDto == null) {
            return Response.error("您的个人信息不存在，请联系管理员添加");
        }
        if (SystemConstants.ABNORMAL.equals(deptPersonDto.getStatus())) {
            return Response.error("用户已被禁用");
        }
        //是否绑定
        OfficialAccountsBindingDto officialAccountsBindingDto = officialAccountsBindingService.selectBy(
                empSession.getOfficialAccountsType(),
                empSession.getAppId(),
                empSession.getOpenId(),
                OfficialAccountsConstants.PERSON_TYPE_EMP
        );
        if (officialAccountsBindingDto == null) {
            //没有绑定
            officialAccountsBindingDto = new OfficialAccountsBindingDto();
            officialAccountsBindingDto.setType(empSession.getOfficialAccountsType());
            officialAccountsBindingDto.setAppId(empSession.getAppId());
            officialAccountsBindingDto.setOpenId(empSession.getOpenId());
            officialAccountsBindingDto.setPersonType(OfficialAccountsConstants.PERSON_TYPE_EMP);
            officialAccountsBindingDto.setPersonId(deptPersonDto.getId());
            officialAccountsBindingDto.setCreateTime(date);
            officialAccountsBindingService.save(officialAccountsBindingDto);
        } else {
            if (!Objects.equals(officialAccountsBindingDto.getPersonId(), deptPersonDto.getId())) {
                //有绑定绑定的不是该用户需用重新绑定
                officialAccountsBindingDto.setPersonId(deptPersonDto.getId());
                officialAccountsBindingService.updateById(officialAccountsBindingDto);
            }
        }

        empSession.setDeptPersonDto(deptPersonDto);

        return Response.<LoginEmpSession>ok().wrap(SessionHolder.resetLoginEmpSession(empSession));
    }

    @PostMapping("JSAPI/accountPasswordLogin")
    @Operation(summary = "公众号账号密码登录")
    public Response<LoginEmpSession> accountPasswordLogin(@RequestBody AccountPasswordLoginVo loginVo) {

        logger.debug("jsapi账号密码登录，请求参数：" + JacksonUtils.toJsonString(loginVo));

        String generateCode = RedisUtils.get(EmpRedisCacheConstants.CAPTCHA_ID + loginVo.getCaptchaId());
        if (StringUtils.isBlank(generateCode)) {
            return Response.error("验证码过期");
        }

        if (!StringUtils.equalsIgnoreCase(generateCode, loginVo.getCaptcha())) {
            return Response.error("验证码错误");
        }

        VillageDto villageDto = villageService.selectByCode(loginVo.getVillageCode());
        if (villageDto == null) {
            return Response.error("当前社区不存在");
        }

        DeptPersonDto dbPerson = deptPersonService.selectByVillageAndMobile(villageDto.getId(), loginVo.getMobile());
        if (dbPerson == null) {
            return Response.error("当前用户不存在");
        }
        if (SystemConstants.NO.equals(dbPerson.getStatus())) {
            return Response.error("当前用户已禁用");
        }


        String wrongCount = RedisUtils.get(EmpRedisCacheConstants.WRONG_INPUT + dbPerson.getId());
        if (StringUtils.isNotBlank(wrongCount) && Long.valueOf(wrongCount) >= EmpRedisCacheConstants.WRONG_NUM) {
            Long ttl = RedisUtils.ttl(EmpRedisCacheConstants.WRONG_INPUT + dbPerson.getId(), TimeUnit.MINUTES);
            return Response.error("该账户已被冻结，请在：" + (ttl <= 0 ? 1 : ttl) + "分钟后登录");
        }
        if (loginVo.getPassword() == null || !PasswordUtils.matchPassword(loginVo.getPassword(), dbPerson.getPassword())) {

            long incr = RedisUtils.incr(EmpRedisCacheConstants.WRONG_INPUT + dbPerson.getId(), 1, EmpRedisCacheConstants.WRONG_LOCK_SECOND, TimeUnit.SECONDS);
            if (incr >= EmpRedisCacheConstants.WRONG_NUM) {
                Long ttl = RedisUtils.ttl(EmpRedisCacheConstants.WRONG_INPUT + dbPerson.getId(), TimeUnit.MINUTES);

                return Response.error("该账户已被冻结，请在：" + (ttl <= 0 ? 1 : ttl) + "分钟后登录");
            }
            return Response.error("密码错误 错误" + (EmpRedisCacheConstants.WRONG_NUM - incr) + "次后该账户将被冻结" + EmpRedisCacheConstants.WRONG_LOCK_SECOND / 60 + "分钟");
        }
        //删除锁定次数
        RedisUtils.del(EmpRedisCacheConstants.WRONG_INPUT + dbPerson.getId());


        LoginEmpSession empSession = SessionHolder.getLoginEmpSession();

        //是否绑定
        OfficialAccountsBindingDto officialAccountsBindingDto = officialAccountsBindingService.selectBy(
                SessionHolder.getLoginEmpSession().getOfficialAccountsType(),
                SessionHolder.getLoginEmpSession().getAppId(),
                SessionHolder.getLoginEmpSession().getOpenId(),
                OfficialAccountsConstants.PERSON_TYPE_EMP
        );
        if (officialAccountsBindingDto == null) {
            //没有绑定
            officialAccountsBindingDto = new OfficialAccountsBindingDto();
            officialAccountsBindingDto.setType(empSession.getOfficialAccountsType());
            officialAccountsBindingDto.setAppId(empSession.getAppId());
            officialAccountsBindingDto.setOpenId(empSession.getOpenId());
            officialAccountsBindingDto.setPersonType(OfficialAccountsConstants.PERSON_TYPE_EMP);
            officialAccountsBindingDto.setPersonId(dbPerson.getId());
            officialAccountsBindingDto.setCreateTime(new Date());
            officialAccountsBindingService.save(officialAccountsBindingDto);
        } else {
            if (!Objects.equals(officialAccountsBindingDto.getPersonId(), dbPerson.getId())) {
                //有绑定绑定的不是该用户需用重新绑定
                officialAccountsBindingDto.setPersonId(dbPerson.getId());
                officialAccountsBindingService.updateById(officialAccountsBindingDto);
            }
        }

        empSession.setDeptPersonDto(dbPerson);

        return Response.<LoginEmpSession>ok().wrap(SessionHolder.resetLoginEmpSession(empSession));
    }

    /**
     * 发送验证码
     *
     * @return
     */
    @PostMapping("sendUpdateMobileMsgCode")
    @Operation(summary = "发送修改手机号验证码")
    public Response<Object> sendUpdatePassMsgCode(@RequestBody SendVerCodeVo sendVerCodeVo) {

        DeptPersonDto deptPersonDto = SessionHolder.getLoginEmpSession().getDeptPersonDto();


        DeptPersonDto dbValue = deptPersonService.selectByVillageAndMobile(deptPersonDto.getVillageId(), sendVerCodeVo.getMobile());

        if (dbValue != null && !Objects.equals(dbValue.getId(), SessionHolder.getLoginEmpSession().getDeptPersonDto().getId())) {
            return Response.error("您修改的手机号被占用");
        }

        String code = smsCompnent.sendVerCode(deptPersonDto.getTenantId(), sendVerCodeVo.getMobile(), SMSConstants.VerCodeType.EMP_EDIT_MOBILE);
        if (code == null) {
            return Response.error("发送验证码失败");
        }
        return Response.ok().wrap(thirdPlatformConfigBusiness.smsMockEnable(deptPersonDto.getTenantId()) ? code : null);
    }


    /**
     * 修改手机
     *
     * @return
     */
    @PostMapping("editMyMobile")
    @Operation(summary = "修改手机")
    public Response<LoginEmpSession> editMobile(@RequestBody EmpBaseInfoWithMobileVo empBaseInfoWithMobileVo) {

        LoginEmpSession loginMobileUserSession = SessionHolder.getLoginEmpSession();

        DeptPersonDto dbValue = deptPersonService.selectByVillageAndMobile(loginMobileUserSession.getDeptPersonDto().getVillageId(), empBaseInfoWithMobileVo.getMobile());
        if (dbValue != null && !Objects.equals(dbValue.getId(), loginMobileUserSession.getDeptPersonDto().getId())) {
            return Response.error("您修改的手机号被占用");
        }

        boolean isLegal = smsCompnent.checkVerCode(empBaseInfoWithMobileVo.getMobile(), empBaseInfoWithMobileVo.getVerCode(), SMSConstants.VerCodeType.EMP_EDIT_MOBILE);
        if (!isLegal) {
            //输入错误就要作废
            smsCompnent.invalidVerCode(empBaseInfoWithMobileVo.getMobile(), SMSConstants.VerCodeType.EMP_EDIT_MOBILE);
            return Response.error("您输入验证码不正确或者不在有效期内,请重新发送");
        }
        //使用以后过期
        smsCompnent.invalidVerCode(empBaseInfoWithMobileVo.getMobile(), SMSConstants.VerCodeType.EMP_EDIT_MOBILE);

        DeptPersonDto deptPersonDto = new DeptPersonDto();
        deptPersonDto.setId(SessionHolder.getLoginEmpSession().getDeptPersonDto().getId());
        deptPersonDto.setMobile(empBaseInfoWithMobileVo.getMobile());
        deptPersonService.updateById(deptPersonDto);

        //重新覆盖session
        loginMobileUserSession.setDeptPersonDto(deptPersonService.selectById(loginMobileUserSession.getDeptPersonDto().getId()));

        return Response.<LoginEmpSession>ok().wrap(SessionHolder.resetLoginEmpSession(loginMobileUserSession));
    }


    /**
     * 修改个人信息
     *
     * @return
     */
    @PostMapping("editPersonalInfo")
    @Operation(summary = "修改个人信息")
    public Response<LoginEmpSession> editInfo(@RequestBody DeptPersonDto deptPersonDto) {

        DeptPersonDto dbValue = deptPersonService.selectById(SessionHolder.getEmp().getId());
        if (dbValue != null) {
            dbValue.setAvatar(deptPersonDto.getAvatar());
            dbValue.setNickname(deptPersonDto.getNickname());
            dbValue.setGender(deptPersonDto.getGender());
        }
        deptPersonService.updateById(dbValue);


        LoginEmpSession loginEmpSession = SessionHolder.getLoginEmpSession();
        loginEmpSession.setDeptPersonDto(dbValue);

        return Response.<LoginEmpSession>ok().wrap(SessionHolder.resetLoginEmpSession(loginEmpSession));
    }

    /**
     * 发送验证码
     *
     * @return
     */
    @PostMapping("sendForgetPasswordMsgCode")
    @Operation(summary = "发送忘记密码验证码")
    public Response<Object> sendUpdatePasswordMsgCode(@RequestBody SendVerCodeVo sendVerCodeVo) {

        VillageDto villageDto = villageService.selectByCode(sendVerCodeVo.getVillageCode());
        if (villageDto == null) {
            return Response.error("当前社区不存在");
        }

        DeptPersonDto dbValue = deptPersonService.selectByVillageAndMobile(villageDto.getId(), sendVerCodeVo.getMobile());

        if (dbValue == null) {
            return Response.error("你的个人信息不存在，无法发送验证码");
        }
        if (SystemConstants.ABNORMAL.equals(dbValue.getStatus())) {
            return Response.error("用户已被禁用");
        }

        String code = smsCompnent.sendVerCode(dbValue.getTenantId(), sendVerCodeVo.getMobile(), SMSConstants.VerCodeType.EMP_EDIT_PASS);
        if (code == null) {
            return Response.error("发送验证码失败");
        }
        return Response.ok().wrap(thirdPlatformConfigBusiness.smsMockEnable(dbValue.getTenantId()) ? code : null);
    }

    /**
     * 重置密码
     *
     * @return
     */
    @PostMapping("resetPassword")
    @Operation(summary = "忘记密码并重置")
    public Response<Object> resetPassword(@RequestBody ResetPasswordVo resetPasswordVo) {

        boolean isLegal = smsCompnent.checkVerCode(resetPasswordVo.getMobile(), resetPasswordVo.getVerCode(), SMSConstants.VerCodeType.EMP_EDIT_PASS);
        if (!isLegal) {
            //输入错误就要作废
            smsCompnent.invalidVerCode(resetPasswordVo.getMobile(), SMSConstants.VerCodeType.EMP_EDIT_PASS);
            return Response.error("您输入验证码不正确或者不在有效期内,请重新发送");
        }
        //使用以后过期
        smsCompnent.invalidVerCode(resetPasswordVo.getMobile(), SMSConstants.VerCodeType.EMP_EDIT_PASS);

        VillageDto villageDto = villageService.selectByCode(resetPasswordVo.getVillageCode());
        if (villageDto == null) {
            return Response.error("社区不存在");
        }

        DeptPersonDto deptPersonDto = deptPersonService.selectByVillageAndMobile(villageDto.getId(), resetPasswordVo.getMobile());
        if (deptPersonDto == null) {
            return Response.error("您的个人信息不存在，请联系管理员添加");
        }

        if (SystemConstants.ABNORMAL.equals(deptPersonDto.getStatus())) {
            return Response.error("用户已被禁用");
        }

        //重置密码后就解除锁定
        RedisUtils.del(EmpRedisCacheConstants.WRONG_INPUT + deptPersonDto.getId());

        DeptPersonDto updateObj = new DeptPersonDto();
        updateObj.setId(deptPersonDto.getId());
        updateObj.setPassword(PasswordUtils.hashpw(resetPasswordVo.getNewPassword()));
        deptPersonService.updateById(updateObj);
        return Response.ok();
    }

    /**
     * 查询是否设置过密码
     *
     * @return
     */
    @GetMapping("hasPassword")
    @Operation(summary = "查询是否设置过密码")
    public Response<PasswordSetInfo> hasPassword() {

        DeptPersonDto dbValue = deptPersonService.selectById(SessionHolder.getEmp().getId());
        if (dbValue == null) {
            return Response.error(SystemConstants.ILLEGAL_MSG);
        }
        PasswordSetInfo passwordSetInfo = new PasswordSetInfo();
        passwordSetInfo.setHasPassword(StringUtils.isNotEmpty(dbValue.getPassword()));
        return Response.<PasswordSetInfo>ok().wrap(passwordSetInfo);
    }

    /**
     * 个人中心修改密码
     *
     * @return
     */
    @PostMapping("updatePassword")
    @Operation(summary = "个人中心修改密码")
    public Response<Object> updatePassword(@RequestBody UpdatePasswordVo updatePasswordVo) {

        DeptPersonDto dbValue = deptPersonService.selectById(SessionHolder.getEmp().getId());
        if (dbValue == null) {
            return Response.error(SystemConstants.ILLEGAL_MSG);
        }
        if (StringUtils.isEmpty(dbValue.getPassword())) {
            //不做操作
        } else {
            if (!PasswordUtils.matchPassword(updatePasswordVo.getOriginalPassword(), dbValue.getPassword())) {
                return Response.error("原密码不正确");
            }
        }

        DeptPersonDto updateObj = new DeptPersonDto();
        updateObj.setId(dbValue.getId());
        updateObj.setPassword(PasswordUtils.hashpw(updatePasswordVo.getNewPassword()));
        deptPersonService.updateById(updateObj);
        return Response.ok();
    }

    @PostMapping("logout")
    @Operation(summary = "退出")
    public Response<Object> logout() {
        LoginEmpSession session = SessionHolder.getLoginEmpSession();
        if (session != null) {
            //删除session
            SessionHolder.logout();

            if (SystemConstants.LoginType.JS_API.getType().equals(SessionHolder.getLoginEmpSession().getLoginType())) {
                //公众号登录
                //解除关系
                OfficialAccountsBindingDto officialAccountsBindingDto = officialAccountsBindingService.selectBy(
                        session.getOfficialAccountsType(),
                        session.getAppId(),
                        session.getOpenId(),
                        OfficialAccountsConstants.PERSON_TYPE_EMP
                );
                if (officialAccountsBindingDto != null) {
                    officialAccountsBindingService.deleteById(officialAccountsBindingDto.getId());
                }
            }

        }
        return Response.ok();
    }


    /**
     * 得到租户下社区
     *
     * @return
     */
    @GetMapping("getVillages")
    @Operation(summary = "得到租户下社区")
    public Response<List<VillageDto>> getParks() {
        Map<String, Object> params = new HashMap<>();

        params.put(LambdaUtil.getFieldName(VillageDto::getTenantId), SessionHolder.getLoginEmpSession().getDeptPersonDto().getTenantId());
        //绑定部分社区
        return Response.<List<VillageDto>>ok().wrap(villageService.queryList(params));

    }


}
